let app = getApp()
Component({
    properties: {
      address: {
        type: String,
        observer: function(newVal, oldVal) {
          this.updateaddress()
        }
      },
      value: {
        type: [ String, Array, Number ],
        default: ""
    },
    mode: {
        type: String,
        default: "date"
    },
    range: {
        type: Array,
        default: function() {
            return [];
        }
    },
    setPlaceholder: {
        type: String,
        default: ""
    },
    code: {
        type: [ Array, Number, String ],
        default: function() {
            return [];
        }
    }
      },
      data:{
        pickerData: [],
        pickerValueKey: [],
        pickerMode: "",
        deep: !1,
        active: {},
        dateArray: [],
        init: !0,
        defaultCode: [],
        region: ['', '', ''],
        itemHeight: "height:48px",
        value: [0, 0, 0],
        address:'请选择所在区域'
      },
    lifetimes: {
        attached: function () {
             this.setData({
              globalColor:app.globalData.globalColor
            })
            if(this.data.address==''){
              this.setData({
                address:'请选择地区'
              })
            }
         }
      },
    methods: {
      updateaddress:function(){
        if(this.data.address==''){
          this.setData({
            address:'请选择地区'
          })
        }
      },
      choose:function(e){
        if(e.detail.area=='110101'){
          var address='北京市 市辖区 东城区'
        }else{
          var address=e.detail.address
        }
        this.setData({
          address:address,
          area:e.detail.area
        })
        var choose=[];
        choose['area']=e.detail.area;
        choose['address']=address;
        choose['pickVal']=e.detail.pickVal;
        this.triggerEvent ('areainfo',choose)
      },
      chooseaddr: function (e) {
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Member_getArea'
          },
          success: function(res) {
             that.setData({
              pickerData:res.data
             })
          }
        })
      },
      bindRegionChange: function (e) {
        var area=[];
        area['region']= e.detail.value;
        area['address']=e.detail.value[0]+' '+e.detail.value[1]+' '+e.detail.value[2];
        area['postcode']=e.detail.postcode;
        this.setData({
          region:area['region'],
          address:area['address'],
          postcode:area['postcode']
        })
        this.triggerEvent ('areainfo',area)
      }
    }
});
